home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / ASBeautifier.h < prev    next >
C/C++ Source or Header  |  2004-06-29  |  6KB  |  168 lines

  1. /*
  2.  * Copyright (c) 1998,1999,2000,2001,2002 Tal Davidson. All rights reserved.
  3.  *
  4.  * compiler_defines.h   (1 January 1999)
  5.  * by Tal Davidson (davidsont@bigfoot.com)
  6.  * This file is a part of "Artistic Style" - an indentater and reformatter
  7.  * of C, C++, C# and Java source files.
  8.  *
  9.  * The "Artistic Style" project, including all files needed to compile it,
  10.  * is free software; you can redistribute it and/or use it and/or modify it
  11.  * under the terms of the GNU General Public License as published 
  12.  * by the Free Software Foundation; either version 2 of the License, 
  13.  * or (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18.  *
  19.  * You should have received a copy of the GNU General Public
  20.  * License along with this program.
  21.  */
  22.  
  23.  
  24. #ifndef ASBEAUTIFIER_H
  25. #define ASBEAUTIFIER_H
  26.  
  27. #include "ASResource.h"
  28. #include "compiler_defines.h"
  29. #include "ASSourceIterator.h"
  30.  
  31. #include <string>
  32. #include <vector>
  33.  
  34.  
  35. using namespace std;
  36.  
  37. namespace astyle
  38.   {
  39.  
  40.   enum BracketMode   { NONE_MODE, ATTACH_MODE, BREAK_MODE, BDAC_MODE };
  41.   enum BracketType   { NULL_TYPE = 0,
  42.                        DEFINITION_TYPE = 1,
  43.                        COMMAND_TYPE = 2,
  44.                        ARRAY_TYPE  = 4,
  45.                        SINGLE_LINE_TYPE = 8};
  46.  
  47.  
  48.   class ASBeautifier : protected ASResource
  49.     {
  50.     public:
  51.       ASBeautifier();
  52.       virtual ~ASBeautifier();
  53.       virtual void init(ASSourceIterator* iter); // pointer to dynamically created iterator.
  54.       virtual void init();
  55.       virtual bool hasMoreLines() const;
  56.       virtual string nextLine();
  57.       virtual string beautify(const string &line);
  58.       void setTabIndentation(int length = 4, bool forceTabs = false);
  59.       void setSpaceIndentation(int length = 4);
  60.       void setMaxInStatementIndentLength(int max);
  61.       void setMinConditionalIndentLength(int min);
  62.       void setClassIndent(bool state);
  63.       void setSwitchIndent(bool state);
  64.       void setCaseIndent(bool state);
  65.       void setBracketIndent(bool state);
  66.       void setBlockIndent(bool state);
  67.       void setNamespaceIndent(bool state);
  68.       void setLabelIndent(bool state);
  69.       void setCStyle();
  70.       void setJavaStyle();
  71.       void setEmptyLineFill(bool state);
  72.       void setPreprocessorIndent(bool state);
  73.  
  74.  
  75.     protected:
  76.       int getNextProgramCharDistance(const string &line, int i);
  77.       bool isLegalNameChar(char ch) const;
  78.       bool isWhiteSpace(char ch) const;
  79.       const string *findHeader(const string &line, int i,
  80.                                const vector<const string*> &possibleHeaders,
  81.                                bool checkBoundry = true);
  82.       string trim(const string &str);
  83.       int indexOf(vector<const string*> &container, const string *element);
  84.  
  85.     private:
  86.       ASBeautifier(const ASBeautifier ©);
  87.       void operator=(ASBeautifier&); // not to be implemented
  88.  
  89.       void initStatic();
  90.       void registerInStatementIndent(const string &line, int i, int spaceTabCount,
  91.                                      int minIndent, bool updateParenStack);
  92.       string preLineWS(int spaceTabCount, int tabCount);
  93.  
  94.       static vector<const string*> headers;
  95.       static vector<const string*> nonParenHeaders;
  96.       static vector<const string*> preprocessorHeaders;
  97.       static vector<const string*> preBlockStatements;
  98.       static vector<const string*> assignmentOperators;
  99.       static vector<const string*> nonAssignmentOperators;
  100.  
  101.       static bool calledInitStatic;
  102.  
  103.       ASSourceIterator *sourceIterator;
  104.       vector<ASBeautifier*> *waitingBeautifierStack;
  105.       vector<ASBeautifier*> *activeBeautifierStack;
  106.       vector<int> *waitingBeautifierStackLengthStack;
  107.       vector<int> *activeBeautifierStackLengthStack;
  108.       vector<const string*> *headerStack;
  109.       vector< vector<const string*>* > *tempStacks;
  110.       vector<int> *blockParenDepthStack;
  111.       vector<bool> *blockStatementStack;
  112.       vector<bool> *parenStatementStack;
  113.       vector<int> *inStatementIndentStack;
  114.       vector<int> *inStatementIndentStackSizeStack;
  115.       vector<int> *parenIndentStack;
  116.       vector<bool> *bracketBlockStateStack;
  117.       string indentString;
  118.       const string *currentHeader;
  119.       const string *previousLastLineHeader;
  120.       const string *immediatelyPreviousAssignmentOp;
  121.       const string *probationHeader;
  122.       bool isInQuote;
  123.       bool isInComment;
  124.       bool isInCase;
  125.       bool isInQuestion;
  126.       bool isInStatement;
  127.       bool isInHeader;
  128.       bool isCStyle;
  129.       bool isInOperator;
  130.       bool isInTemplate;
  131.       bool isInConst;
  132.       bool isInDefine;
  133.       bool isInDefineDefinition;
  134.       bool classIndent;
  135.       bool isInClassHeader;
  136.       bool isInClassHeaderTab;
  137.       bool switchIndent;
  138.       bool caseIndent;
  139.       bool namespaceIndent;
  140.       bool bracketIndent;
  141.       bool blockIndent;
  142.       bool labelIndent;
  143.       bool preprocessorIndent;
  144.       bool isInConditional;
  145.       bool isMinimalConditinalIndentSet;
  146.       bool shouldForceTabIndentation;
  147.       int minConditionalIndent;
  148.       int parenDepth;
  149.       int indentLength;
  150.       int blockTabCount;
  151.       unsigned int leadingWhiteSpaces;
  152.       int maxInStatementIndent;
  153.       int templateDepth;
  154.       char quoteChar;
  155.       char prevNonSpaceCh;
  156.       char currentNonSpaceCh;
  157.       char currentNonLegalCh;
  158.       char prevNonLegalCh;
  159.       int prevFinalLineSpaceTabCount;
  160.       int prevFinalLineTabCount;
  161.       bool emptyLineFill;
  162.       bool backslashEndsPrevLine;
  163.       int defineTabCount;
  164.     };
  165. }
  166.  
  167. #endif
  168.